﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Sales_SalesSearch : ATPages
{
    Function f = new Function();
    protected void Page_Load(object sender, EventArgs e)
    {
        lblPath.Text = f.getModuleidAdd(Request["moduid"]);
        txtKdate.Attributes.Add("onclick", "SelectDate('txtKdate')");
        txtJdate.Attributes.Add("onclick", "SelectDate('txtJdate')");
        if (!IsPostBack)
        {
            HidWareid.Value=getWareId();
            initKdate();
            initData();
        }
    }
    private void initData()
    {
        string sql = "select SalesCode,typeStock,comodid,Convert(char(10),C_date,120) as cdate,GuestName,a.WarehouseId,comodName,modul,unit,comodBarcode,prices,number,discount,TotalMoney,a.deptid,realname from CS_Sales a join CS_Guest b on a.guestid=b.guestid join UserInfo c on a.userid=c.userid where typeSale=2 and a.deptid=" + Request.Cookies["user"].Values["deptid"] + "";
        PageNavigator1.Total=1;
        PageNavigator1.Query = sql;
      
        
    }
    private string getWareId()
    {
        ZSql zs = new ZSql();
        string sql = "select WarehouseId from UserInfo where userid=" + Request.Cookies["user"].Values["id"];
        zs.Open(sql);

        zs.Close();
        return zs.m_table.Rows[0]["WarehouseId"].ToString();
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {

        string sql = "select SalesCode,typeStock,comodid,Convert(char(10),C_date,120) as cdate,GuestName,a.WarehouseId,comodName,modul,unit,comodBarcode,prices,number,discount,TotalMoney,a.deptid,realname from CS_Sales a join CS_Guest b on a.guestid=b.guestid join UserInfo c on a.userid=c.userid where typeSale=2 and a.deptid=" + Request.Cookies["user"].Values["deptid"] + "";
        if (!string.IsNullOrEmpty(txtdh.Text))
        {
            sql += " and SalesCode like'%" + Common.FormatParameter(txtdh.Text) + "%'";
        }
        if (!string.IsNullOrEmpty(txtSalesCode.Text))
        {
            sql += " and modul like'%" + Common.FormatParameter(txtSalesCode.Text) + "%'";
        }
        if (!string.IsNullOrEmpty(txtGuest.Text))
        {
            sql += " and b.GuestName like'%"+Common.FormatParameter(txtGuest.Text)+"%'";
        }
        if (!string.IsNullOrEmpty(txtKdate.Text) && !string.IsNullOrEmpty(txtJdate.Text.Trim()))
        {
            sql += " and C_date >='" + Common.FormatParameter(txtKdate.Text) + " 00:00:00' and C_date<='" + Common.FormatParameter(txtJdate.Text) + " 23:59:59'";
        }
        //if (HidWareid.Value != "0")
        //{

            //sql += " and warehouse=" + HidWareid.Value;
        //}
        //lblPath.Text = sql;
        PageNavigator1.Total = 1;
        PageNavigator1.Query = sql;
    }
    protected void linkbtnSales_Click(object sender, EventArgs e)
    {
        string id = (sender as LinkButton).CommandArgument;
        ClientScript.RegisterStartupScript(typeof(Page), "aa", "PrintData('" + id + "')",true);
    }
    private void initKdate() 
    {

        txtJdate.Text = DateTime.Now.Date.ToString("yyyy-MM-dd");//当前日期
        txtKdate.Text = DateTime.Now.Date.ToString("yyyy-MM") + "-01";//当月的第一天
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ClientScript.RegisterStartupScript(typeof(Page), "aa", "AllPrintData('" + txtKdate.Text + "','" + txtJdate.Text + "','" + txtGuest.Text + "','" + txtSalesCode.Text + "','" + txtdh.Text + "')", true);
    }
}
